package com.xhsj.user.pms.overseas.web;

import com.xhsj.user.pms.overseas.dto.MonitorListDto;
import com.xhsj.user.pms.overseas.query.CaseTreeListQuery;
import com.xhsj.user.pms.overseas.query.TimeLimitNameQuery;
import com.xhsj.user.utils.Message;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.*;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;


import com.xhsj.user.pms.overseas.service.TbPamOverseasRegionalDetailsService;
import com.xhsj.user.pms.overseas.entity.TbPamOverseasRegionalDetails;

import javax.validation.Valid;


/**
 * <p>
 * 专利模块海外地区时间详情表 前端控制器
 * </p>
 *
 * @author liuqinghua
 * @since Jan 22, 2021 11:41:13 AM
 */
@Slf4j
@Api(tags = "专利模块海外地区时间详情表")
@RestController
@RequestMapping("/overseas/tbPamOverseasRegionalDetails")
public class TbPamOverseasRegionalDetailsController {

	@Autowired
    public TbPamOverseasRegionalDetailsService service;


	/**
	 * 保存/修改
	 * @author liuqinghua
	 * @date Jan 22, 2021 11:41:13 AM
	 */
	@ApiOperation(value = "专利模块海外地区时间详情表,保存/修改", notes = "专利模块海外地区时间详情表,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:pam:overseas:regional:details:edit')")
	public Message save(@RequestBody TbPamOverseasRegionalDetails data){
    	try {
    		service.save(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,"失败");
		}

	}

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Jan 22, 2021 11:41:13 AM
	 */
	@ApiOperation(value = "专利模块海外地区时间详情表删除", notes = "通过id删除专利模块海外地区时间详情表信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('tb:pam:overseas:regional:details:delete')")
	public Message delete(@RequestParam(value="id") Long id) {
		try {
			service.removeById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}

	}

	/**
	 * 批量删除
	 * @author liuqinghua
	 * @date Jan 22, 2021 11:41:13 AM
	 */
	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('tb:pam:overseas:regional:details:delete')")
	public Message batchDelete(@RequestBody List<Long> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }

    /**
    * 分页查询数据
    * @author liuqinghua
    * @date Jan 22, 2021 11:41:13 AM
    */
	@ApiOperation(value = "分页查询专利模块海外地区时间详情表list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:pam:overseas:regional:details:view')")
	public Message findList(@RequestBody Map<String,Object> data) {
        try {
        	IPage<TbPamOverseasRegionalDetails> selectPage = service.selectPage(data);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

    /**
    * 查询所有数据
    * @author liuqinghua
    * @date Jan 22, 2021 11:41:13 AM
    */
	@ApiOperation(value = "查询专利模块海外地区时间详情表所有数据list", notes = "查询专利模块海外地区时间详情表所有数据list。")
	@RequestMapping(value="/findAll",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:pam:overseas:regional:details:view')")
	public Message findAll(){
        return Message.success("成功",service.selectAll());
	}

    /**
    * 通过id获取实体类
    * @author liuqinghua
    * @date Jan 22, 2021 11:41:13 AM
    */
	@ApiOperation(value = "通过id获取专利模块海外地区时间详情表实体类", notes = "通过id获取专利模块海外地区时间详情表实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
	public Message getById(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

    /**
    * 通过id查询详细信息
    * @author liuqinghua
    * @date Jan 22, 2021 11:41:13 AM
    */
	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
	public Message detail(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

	/**
	 *国内案件提醒列表
	 * @author liuqinghua
	 * @date Jan 22, 2021 11:41:13 AM
	 */
	@ApiOperation(value = "国内案件提醒列表", notes = "国内案件提醒列表")
    @PreAuthorize("hasAuthority('tb:pam:overseas:monitor:list:view')")
	@PostMapping(value="/monitorList")
	public Message monitorList(@RequestBody @Valid MonitorListDto param, BindingResult bindingResult) {
        log.info("国内案件提醒列表参数{}", param);
        if (bindingResult.hasErrors()) {
            log.info(bindingResult.getFieldError().getDefaultMessage());
            return Message.error(1,bindingResult.getFieldError().getDefaultMessage());
        }
        IPage<Map<String,Object>> timeLimitNameQueryIPage = service.monitorList(param);
        return Message.success("成功",timeLimitNameQueryIPage.getRecords(),timeLimitNameQueryIPage.getTotal(),timeLimitNameQueryIPage.getPages());
	}

    /**
     *国内案件提醒数量
     * @author liuqinghua
     * @date Jan 22, 2021 11:41:13 AM
     */
    @ApiOperation(value = "国内案件提醒数量", notes = "国内案件提醒数量")
    @GetMapping(value="/monitorListNum")
    public Message monitorListNum(@RequestParam(value = "type") Integer type) {
        log.info("国内案件提醒数量参数{}", type);
        int num = service.monitorListNum(type);
        return Message.success("成功",num);
    }

       /**
           * @Description:  获取案件提醒类型
           * @Param:  无
           * @return:  List<Map<String, Object>>
           * @Author: liuqinghua
           * @Date: 2021/2/2
           */
	   @ApiOperation(value = "获取案件提醒类型", notes = "获取案件提醒类型")
	   @GetMapping(value="/getMonitorType")
	   public Message getMonitorType() {
           List<Map<String, Object>> monitorType = service.getMonitorType();
           return Message.success("成功",monitorType);
	   }

}

